<?php

namespace app\admin\controller\sys;
use app\admin\controller\Base;
use think\facade\Request;
use think\facade\View;

class SystemLog extends Base
{
    protected $model;
    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\admin\model\sys\SystemLog;
    }
    public function index(){
        if (Request::isPost()) {
            $keys=$this->request->post();

            $where = [];
            if ($keys['username']) {
                $where[] = array('username','like','%'.$keys['username'].'%');
            }

            if ($keys['url']) {
                $where[] = array('url','like','%'.$keys['url'].'%');
            }
            if ($keys['sstarttime']) {
                $where[] = array('dateline','>=',strtotime($keys['sstarttime']));
            }
            if ($keys['sendtime']) {
                $where[] = array('dateline','<=',strtotime($keys['sendtime'])+86399);
            }
            $option = [
                'where' => $where,
            ];
            $list = $this->model->loadList($option);
            if ($list['result'] == 'success'){
                $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['list'], 'count' => $list['page']['total']];
            }else{
                $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => [], 'count' => 0];
            }
            return $result;
        }
        return view();
    }
    public function logform(){
        $id = input('param.id');
        $info = $this->model->where('id='.$id)->find();
        $info['param'] = json_decode($info['param'],true);
        View::assign('info',$info);
        return view();
    }

}